package com.xieyingwangluo.yxpart.utils;

import org.springframework.context.ApplicationContext;

public class SpringContextHandler {

    private static ApplicationContext applicationContext;
    /**
     * 根据类名获取Spring管理的Bean
     * @param clz
     * @return
     */
    public static <T> T getBean(Class<T> clz){
        if(applicationContext==null){
            return null;
        }
        T obj = applicationContext.getBean(clz);
        return obj;
    }

    public static void setApplicationContext(ApplicationContext ctx){
        applicationContext=ctx;
    }
}
